# CMake makefile
# Project: OpenPool
# Author: R. Marson

PROJECT(OPENPOOL)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(EXE_NAME OpenPool)

SET(CMAKE_BUILD_TYPE Release)

SET(SRC_DIR ${OPENPOOL_SOURCE_DIR}/src)
SET(HDRS_DIR ${OPENPOOL_SOURCE_DIR}/headers)
SET(DEPLOY_DIR ${OPENPOOL_SOURCE_DIR}/bin)
SET(DEPEND_DIR ${OPENPOOL_SOURCE_DIR}/dependencies)

IF(APPLE)
INCLUDE_DIRECTORIES(/usr/local/include)
ENDIF(APPLE)

INCLUDE_DIRECTORIES(${DEPEND_DIR})
INCLUDE_DIRECTORIES(${HDRS_DIR} ${HDRS_DIR}/obj ${HDRS_DIR}/script ${HDRS_DIR}/math)

SET(POOL_SRC ${SRC_DIR}/obj/model_obj.cpp
	    ${SRC_DIR}/script/as_addon/scriptbuilder.cpp
	    ${SRC_DIR}/script/as_addon/scriptstdstring.cpp
	    ${SRC_DIR}/script/as_addon/scriptstdstring_utils.cpp
	    ${SRC_DIR}/script/as_addon/scriptarray.cpp
	    ${SRC_DIR}/script/as_addon/scriptdictionary.cpp
	    ${SRC_DIR}/script/scriptmanager.cpp
	    ${SRC_DIR}/script/gameoptions.cpp
	    ${SRC_DIR}/script/gametypes.cpp
	    ${SRC_DIR}/math/CVector2.cpp
	    ${SRC_DIR}/math/CVector3.cpp
	    ${SRC_DIR}/math/CMatrix3x3.cpp
	    ${SRC_DIR}/math/CMatrix4x4.cpp
	    ${SRC_DIR}/math/CQuaternion.cpp
	    ${SRC_DIR}/material.cpp 
	    ${SRC_DIR}/globjects.cpp 
	    ${SRC_DIR}/objects.cpp
	    ${SRC_DIR}/events.cpp
	    ${SRC_DIR}/logmanager.cpp
	    ${SRC_DIR}/eventmanager.cpp
	    ${SRC_DIR}/rescache.cpp
	    ${SRC_DIR}/logic.cpp
	    ${SRC_DIR}/physics.cpp
	    ${SRC_DIR}/glengine.cpp
	    ${SRC_DIR}/soundsystem.cpp
	    ${SRC_DIR}/mainoptions.cpp
	    ${SRC_DIR}/application.cpp
	    ${SRC_DIR}/main.cpp )

SET(POOL_HDRS ${HDRS_DIR}/obj/model_obj.h 
	      ${HDRS_DIR}/script/as_addon/scriptbuilder.h
	      ${HDRS_DIR}/script/as_addon/scriptstdstring.h
	      ${HDRS_DIR}/script/as_addon/scriptarray.h
	      ${HDRS_DIR}/script/as_addon/scriptdictionary.h
	      ${HDRS_DIR}/script/scriptmanager.h
	      ${HDRS_DIR}/script/gameoptions.h
	      ${HDRS_DIR}/script/gametypes.h
	      ${HDRS_DIR}/math/Constants.h
	      ${HDRS_DIR}/math/CVector2.h	
	      ${HDRS_DIR}/math/CVector3.h
	      ${HDRS_DIR}/math/CMatrix3x3.h
	      ${HDRS_DIR}/math/CMatrix4x4.h
	      ${HDRS_DIR}/math/CQuaternion.h
	      ${HDRS_DIR}/enumerations.h
	      ${HDRS_DIR}/interfaces.h 
	      ${HDRS_DIR}/material.h
	      ${HDRS_DIR}/globjects.h
	      ${HDRS_DIR}/objects.h
	      ${HDRS_DIR}/events.h      
	      ${HDRS_DIR}/logmanager.h
	      ${HDRS_DIR}/eventmanager.h
	      ${HDRS_DIR}/rescache.h
	      ${HDRS_DIR}/logic.h
	      ${HDRS_DIR}/physics.h
	      ${HDRS_DIR}/glengine.h
	      ${HDRS_DIR}/soundsystem.h
	      ${HDRS_DIR}/mainoptions.h
	      ${HDRS_DIR}/application.h )

ADD_EXECUTABLE(${EXE_NAME} ${POOL_SRC} ${POOL_HDRS})

SET(LINK_DIR ${DEPEND_DIR}/libs)

SET(DEPLOY_DIR ${OPENPOOL_SOURCE_DIR}/bin)

IF(UNIX)
IF(APPLE)
INCLUDE_DIRECTORIES(${LINK_DIR})
FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
SET(EXTRA_LIBS ${OPENGL_LIBRARY} 
	      ${LINK_DIR}/sfml-system.framework
	      ${LINK_DIR}/sfml-window.framework
	      ${LINK_DIR}/sfml-graphics.framework
	      ${LINK_DIR}/sfml-audio.framework
	      ${LINK_DIR}/libfreeimage-3.13.1.dylib 
	      ${LINK_DIR}/libphysfs.2.0.2.dylib 
	      ${LINK_DIR}/libAngelscript.a
	      ${LINK_DIR}/libGLEW.a  )
ELSE(APPLE)
SET(EXTRA_LIBS ${LINK_DIR}/libsfml-system.so
	      ${LINK_DIR}/libsfml-window.so 
	      ${LINK_DIR}/libsfml-graphics.so
	      ${LINK_DIR}/libsfml-audio.so
	      ${LINK_DIR}/libfreeimage.so
	      ${LINK_DIR}/libphysfs.so
	      ${LINK_DIR}/libAngelscript.a
	      GL 
	      GLU
	      GLEW )
ENDIF(APPLE)
ELSE(UNIX)
SET(EXTRA_LIBS ${LINK_DIR}/libsfml-system.a
	      ${LINK_DIR}/libsfml-window.a
	      ${LINK_DIR}/libsfml-graphics.a
	      ${LINK_DIR}/libsfml-audio.a
	      ${LINK_DIR}/libglew32.dll.a
	      ${LINK_DIR}/FreeImage.lib
	      ${LINK_DIR}/libphysfs.dll.a
	      ${LINK_DIR}/libAngelscript.a
	      libopengl32.a
	      libglu32.a	)
ENDIF(UNIX)

TARGET_LINK_LIBRARIES(${EXE_NAME} ${CMAKE_REQUIRED_LIBRARIES} ${EXTRA_LIBS})


IF(UNIX)
IF(APPLE)
SET_PROPERTY(TARGET ${EXE_NAME} PROPERTY MACOSX_BUNDLE TRUE)
INSTALL(TARGETS ${EXE_NAME} BUNDLE DESTINATION ${DEPLOY_DIR})
INSTALL(DIRECTORY ${DEPLOY_DIR} DESTINATION ${EXE_NAME}.app/Contents/MacOS USE_SOURCE_PERMISSIONS)
ELSE(APPLE)
INSTALL(TARGETS ${EXE_NAME} RUNTIME DESTINATION ${DEPLOY_DIR})
ENDIF(APPLE)
ELSE(UNIX)
INSTALL(TARGETS ${EXE_NAME} RUNTIME DESTINATION ${DEPLOY_DIR})
ENDIF(UNIX)

IF(UNIX)
IF(APPLE)
ADD_CUSTOM_COMMAND(TARGET ${EXE_NAME} POST_BUILD COMMAND ./deploy_mac.sh)
ELSE(APPLE)
ADD_CUSTOM_COMMAND(TARGET ${EXE_NAME} POST_BUILD COMMAND ./deploy_lnx.sh)
ENDIF(APPLE)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(TARGET ${EXE_NAME} POST_BUILD COMMAND ./deploy_win.bat)
ENDIF(UNIX)
